package org.dao.daoImp;

import java.util.List;

import org.dao.KcDao;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.model.Kcb;
import org.model.Zyb;

public class KcDaoImp implements KcDao {

	public List getAll() {
		Session session=org.util.HibernateSessionFactory.getSession();
		Transaction ts=session.beginTransaction();
		List list=session.createQuery("from Kcb order by kch").list();
		ts.commit();
		org.util.HibernateSessionFactory.closeSession();
		return list;
	}

	public Kcb getOneKc(String kch) {
		Session session=org.util.HibernateSessionFactory.getSession();
		Transaction ts=session.beginTransaction();
		Query query=session.createQuery("from Zyb where kch=?");
		query.setParameter(0, kch);
		query.setMaxResults(1);
		Kcb kc=(Kcb)query.uniqueResult();
		ts.commit();
		session.clear();
		return kc;
	}

}
